/**
 * 查询
 */
function pageInfo() {
    let userRole = $(".userRole").text();
    $(".tab1 tr:gt(0) td").html("&nbsp;");
    let payStandardCode = $(".payStandardCode").val();
    let checkState = $(".checkState").val();
    let startDate = $(".startDate").val();
    let endDate = $(".endDate").val();
    if (payStandardCode == "" || payStandardCode == null) {
        payStandardCode = null;
    }
    ;
    if (checkState == 0 || checkState == null) {
        checkState = 0;
    }

    if (startDate == "" || startDate == null) {
        startDate = null;
    }

    if (endDate == "" || endDate == null) {
        endDate = null;
    }

    let jsonA = {
        payStandardCode: payStandardCode,
        checkState: checkState,
        startDate: startDate,
        endDate: endDate,
    };
    $.ajaxSettings.async = false;
    $("#noshow").html(
        "<tr>" +
        "<th>薪酬标准编码</th>" +
        "<th>薪酬标准名称</th>" +
        "<th>审核状态</th>" +
        "<th>登记时间</th>" +
        "<th>操作</th>" +
        " </tr>")
    if (userRole == "薪酬专员" || userRole == "人事专员") {
        $(".shanchujilu").html("<a href=\"/sal/add\" ><button class=\"layui-btn layui-btn-radius\">标准登记</button></a><a href=\"/sal/seldel\" >     <button class=\"layui-btn layui-btn-radius\" >删除记录</button></a>")
        $.getJSON("/sal/selby", jsonA, function (dataA) {
            console.log(dataA);

            $(dataA).each(function (i, v) {
                console.log(v);
                let date = new Date(v.hour);
                date.setTime(date);
                //let Time=new SimpleDateFormat().format(date)new SimpleDateFormat().format(date);
                let Year = date.getFullYear();
                let Month = date.getMonth() + 1;
                let Day = date.getDate();
                let Hour1 = date.getHours();
                let Min = date.getMinutes();
                let sen = date.getSeconds();
                let Time = Year + "-" + Month + "-" + Day;
                if (v.checkState == "起草" || v.checkState == "驳回") {
                    $("#noshow").append(
                        "<tr style='text-align: center'>" +
                        "<td style='text-align: center'>" + v.payStandardCode + "</td>" +
                        "<td style='text-align: center'>" + v.nameOfSalary + "</td>" +
                        "<td style='text-align: center'>" + v.checkState + "</td>" +
                        "<td style='text-align: center'>" + Time + "</td>" +
                        "<td style='padding-left:75px;' align='left'>" + "<a href='/sal/upd/" + v.id + "'class=''><button style='width:100px' class='layui-btn layui-btn-warm'>修改</button></a>&nbsp;&nbsp;"
                        + "<a href='/sal/selbyid/" + v.id + "'class=''><button style='width:100px' class='layui-btn layui-btn-nomarl'>明细</button></a>&nbsp;&nbsp;"
                        + "<a href='#'class=''><button style='width:100px' class='layui-btn layui-btn-danger'  onclick='ale1(" + v.id + ")'>删除</button></a>&nbsp;&nbsp;"
                        + "</td>"
                        + "</tr>"
                    )
                }
                if (v.checkState == "审核中") {
                    $("#noshow").append(
                        "<tr>" +
                        "<td>" + v.payStandardCode + "</td>" +
                        "<td>" + v.nameOfSalary + "</td>" +
                        "<td>" + v.checkState + "</td>" +
                        "<td>" + Time + "</td>" +
                        "<td style='padding-left:75px;' align='left'>"
                        + "<a href='/sal/selbyid/" + v.id + "'class=''><button style='width:100px' class='layui-btn layui-btn-normal'>明细</button></a>&nbsp;&nbsp;"
                        + "</td>"
                        + "</tr>"
                    )
                }
                if (v.checkState == "审核通过") {
                    $("#noshow").append(
                        "<tr>" +
                        "<td>" + v.payStandardCode + "</td>" +
                        "<td>" + v.nameOfSalary + "</td>" +
                        "<td>" + v.checkState + "</td>" +
                        "<td>" + Time + "</td>" +
                        "<td style='padding-left:75px;' align='left'>"
                        + "<a href='/sal/upd/" + v.id + "'class=''><button style='width:100px' class='layui-btn layui-btn-warm'>变更</button></a>&nbsp;&nbsp;"
                        + "<a href='/sal/selbyid/" + v.id + "'class=''><button style='width:100px' class='layui-btn layui-btn-normal'>明细</button></a>&nbsp;&nbsp;"
                        + "</td>"
                        + "</tr>"
                    )
                }

            })
        })
    } else if (userRole == "公司领导" || userRole == "薪酬经理" || userRole == "系统管理员" || userRole == "人力资源部负责人" || userRole == "人事经理") {
        $.getJSON("/sal/selby", jsonA, function (dataA) {

            console.log(dataA);

            $(dataA).each(function (i, v) {
                console.log(v);
                let date = new Date(v.hour);
                let Year = date.getFullYear();
                let Month = date.getMonth() + 1;
                let Day = date.getDate();
                // let Hour1 = date.getHours();
                // let Min = date.getMinutes();
                // let sen = date.getSeconds();
                let Time = Year + "-" + Month + "-" + Day
                if (v.checkState == "审核中") {
                    $("#noshow").append(
                        "<tr>" +
                        "<td>" + v.payStandardCode + "</td>" +
                        "<td>" + v.nameOfSalary + "</td>" +
                        "<td>" + v.checkState + "</td>" +
                        "<td>" + Time + "</td>"
                        + "<td>"
                        + "<a href='/sal/selagreeid/" + v.id + "'class=''><button style='width:100px' class='layui-btn layui-btn-normal'>明细</button></a>&nbsp;&nbsp;"
                        + "</td>"
                        + "</tr>"
                    )
                }
                if (v.checkState == "审核通过") {
                    $("#noshow").append(
                        "<tr>" +
                        "<td>" + v.payStandardCode + "</td>" +
                        "<td>" + v.nameOfSalary + "</td>" +
                        "<td>" + v.checkState + "</td>" +
                        "<td>" + Time + "</td>" +
                        "<td>"
                        + "<a href='/sal/selbyid/" + v.id + "'class=''><button style='width:100px' class='layui-btn layui-btn-normal'>明细</button></a>&nbsp;&nbsp;"
                        + "</td>"
                        + "</tr>"
                    )
                }

            })
        })
    }
    $.ajaxSettings.async = true;
}

function ale1(id) {
    let con = confirm("确定要删除吗？")
    if (con == true) {
        let jsonA = {
            id: id
        }
        $.ajaxSettings.async = false;
        $.getJSON("/sal/del", jsonA, function (dataA) {
            if (dataA = true) {
                alert("删除成功")
                pageInfo();
            } else {
                alert("删除失败")
                return;
            }
        })
    } else {
        return;
    }
    $.ajaxSettings.async = true;
}

function seldel() {
    $(".tab1 tr:gt(0) td").html("&nbsp;");
    let payStandardCode = $(".payStandardCode").val();
    let checkState = "删除";
    let startDate = $(".startDate").val();
    let endDate = $(".endDate").val();
    if (payStandardCode == "" || payStandardCode == null) {
        payStandardCode = null;
    }
    ;
    if (checkState == 0 || checkState == null) {
        checkState = 0;
    }

    if (startDate == "" || startDate == null) {
        startDate = null;
    }

    if (endDate == "" || endDate == null) {
        endDate = null;
    }

    let jsonA = {
        payStandardCode: payStandardCode,
        startDate: startDate,
        endDate: endDate,
    };
    $.ajaxSettings.async = false;
    $("#noshow").html(
        "<tr>" +
        "<th>薪酬标准编码</th>" +
        "<th>薪酬标准名称</th>" +
        "<th>审核状态</th>" +
        "<th>登记时间</th>" +
        "<th>操作</th>" +
        " </tr>")

    $.getJSON("/sal/seldelby", jsonA, function (dataA) {
        console.log(dataA);
        $(dataA).each(function (i, v) {

            console.log(v);
            let date = new Date(v.hour);
            let Year = date.getFullYear();
            let Month = date.getMonth() + 1;
            let Day = date.getDate();
            // let Hour1 = date.getHours();
            // let Min = date.getMinutes();
            // let sen = date.getSeconds();
            let Time = Year + "-" + Month + "-" + Day
            $("#noshow").append(
                "<tr>" +
                "<td>" + v.payStandardCode + "</td>" +
                "<td>" + v.nameOfSalary + "</td>" +
                "<td>" + v.checkState + "</td>" +
                "<td>" + Time + "</td>" +
                "<td style='padding-left:75px;' align='left'>" + "<a href=''class=''><button style='width:100px' class='layui-btn layui-btn-warm' onclick='resave(" + v.id + ")'>还原</button></a>&nbsp;&nbsp;"
                + "<a href='/sal/selbyid/" + v.id + "'class=''><button style='width:100px' class='layui-btn layui-btn-normal'>明细</button></a>&nbsp;&nbsp;"
                + "<a href='#'class=''><button style='width:100px' class='layui-btn layui-btn-danger'  onclick='finaldel(" + v.id + ")'>删除</button></a>&nbsp;&nbsp;"
                + "</td>"
                + "</tr>"
            )
        })

    })

}


function delall() {
    let con = confirm("删除后将无法复原，请谨慎选择，确认要删除吗？")
    $.ajaxSettings.async = false;
    $.getJSON("/sal/delall", function (dataA) {
        if (dataA = true) {
            alert("清除成功")
            seldel();
        } else {
            alert("清除失败")
            return;
        }
    })

    $.ajaxSettings.async = true;
}

function finaldel(id) {
    let con = confirm("删除后将无法复原，确认要删除吗？")
    if (con == true) {
        let jsonA = {
            id: id
        }
        $.ajaxSettings.async = false;
        $.getJSON("/sal/finaldel", jsonA, function (dataA) {
            if (dataA = true) {
                alert("删除成功")
                seldel();
            } else {
                alert("删除失败")
                return;
            }
        })
    } else {
        return;
    }
    $.ajaxSettings.async = true;
}

function resave(id) {
    let con = confirm("确定要还原吗？")
    if (con == true) {
        let jsonA = {
            id: id
        }
        $.ajaxSettings.async = false;
        $.getJSON("/sal/resave", jsonA, function (dataA) {
            if (dataA = true) {
                alert("还原成功")
                seldel();
            } else {
                alert("还原失败")
                return;
            }
        })
    } else {
        return;
    }
    $.ajaxSettings.async = true;
}


